package com.example.demo;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Service
public class WelcomeService{


  @Autowired
  private UserDao userDao;

  public String hello(long id){

    String userName;
    try {
      User user=userDao.findOne(id);
      userName=user.getName();
    }
    catch(Exception ex){
      return "User not found";
    }


    return "Hello World!" + " :" +userName;
  }

  public String update(long id,User user){

    try {
      User oldUser = userDao.findOne(id);

        oldUser.setName(user.getName());
       userDao.save(oldUser);

    }catch(Exception ex){
      return "Error updating the user: " + ex.toString();
    }



    return "User successfully updated!";
  }
}
